import 'package:fish_redux/fish_redux.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:oktoast/oktoast.dart';
import 'package:school_safe_teacher/base/base_entity.dart';
import 'package:school_safe_teacher/constans/constants.dart';
import 'package:school_safe_teacher/login/entity/login_entity.dart';
import 'package:school_safe_teacher/network/dio_api.dart';
import 'package:school_safe_teacher/network/http_api.dart';
import 'package:school_safe_teacher/utils/sp_utils.dart';

import 'action.dart';
import 'state.dart';

Effect<HomeWorkState> buildEffect() {
  return combineEffects(<Object, Effect<HomeWorkState>>{
    HomeWorkAction.action: _onAction,
    HomeWorkAction.onupdateHomework: _onupdateHomework,
  });
}

void _onAction(Action action, Context<HomeWorkState> ctx) {
}

void _onupdateHomework(Action action, Context<HomeWorkState> ctx) {
    _request(ctx, ctx.state.textValue);
}

Future<void> _request(Context<HomeWorkState> ctx, String task_content) async {
  Map<String, String> params = Map();
  params["task_content"] = task_content;

  params["class_id"] = await SpUtil.getStringItem(Constants.classID);
  DioApi.instance.asyncRequestNetwork<BaseEntity>(
      Method.post,
      HttpApi.PUSHTASK,ctx.context,
      params: params, onStart: () {
    println('请求开始');
    EasyLoading.show(status: 'loading...');
  }, onSuccess: (dynamic t) async {
    showToast("上传成功");
  }, onError: (String msg) {
    println('请求报错 msg:$msg');
    showToast(msg);
  }, onDone: () {
    EasyLoading.dismiss();
  }, isList: false);
}